package com.yc.study.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.study.entity.Topic;
import com.yc.study.service.ITopicService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 前端控制器
 *
 * @author 王妍
 * @since 2022-02-20
 */
@RestController
@RequestMapping("/study/topic")
@AllArgsConstructor
public class TopicController {
  private final ITopicService topicService;

  @PostMapping
  public void save(@RequestBody Topic topic) {
    topicService.saveOrUpdate(topic);
  }

  @GetMapping("/page")
  public Page<Topic> getPage(Page<Topic> topicPage, Topic topic) {
    return topicService.loadPage(topicPage, topic);
  }

  @DeleteMapping
  public void delete(@RequestBody Long[] topicIds) {
    topicService.removeBatchByIds(Arrays.asList(topicIds));
  }

  @GetMapping("/job")
  public List<Topic> getTopicListByTopicIds(Long jobId) {
    return topicService.getTopicListByJobId(jobId);
  }
}
